#!/bin/bash
# 依赖检查脚本

echo "🔍 会说话的键盘 - 依赖检查工具"
echo "=================================="

# 检查Python3
echo "🐍 检查Python3..."
if command -v python3 &> /dev/null; then
    PYTHON_VERSION=$(python3 --version 2>&1)
    echo "✅ $PYTHON_VERSION"
else
    echo "❌ 未找到Python3"
    echo "请安装Python3:"
    echo "  Ubuntu/Debian: sudo apt install python3 python3-pip"
    echo "  CentOS/RHEL: sudo yum install python3 python3-pip"
    echo "  Fedora: sudo dnf install python3 python3-pip"
    echo "  Arch: sudo pacman -S python python-pip"
    exit 1
fi

# 检查pip3
echo "📦 检查pip3..."
if command -v pip3 &> /dev/null; then
    PIP_VERSION=$(pip3 --version 2>&1)
    echo "✅ $PIP_VERSION"
else
    echo "❌ 未找到pip3"
    echo "请安装pip3:"
    echo "  Ubuntu/Debian: sudo apt install python3-pip"
    echo "  CentOS/RHEL: sudo yum install python3-pip"
    echo "  Fedora: sudo dnf install python3-pip"
    echo "  Arch: sudo pacman -S python-pip"
    exit 1
fi

# 检查Python依赖库
echo "🔧 检查Python依赖库..."
python3 -c "import pynput" 2>/dev/null
if [ $? -eq 0 ]; then
    echo "✅ pynput 已安装"
else
    echo "❌ pynput 未安装"
    echo "安装命令: pip3 install pynput"
fi

python3 -c "import pygame" 2>/dev/null
if [ $? -eq 0 ]; then
    echo "✅ pygame 已安装"
else
    echo "❌ pygame 未安装"
    echo "安装命令: pip3 install pygame"
fi

# 检查音频文件
echo "🎵 检查音频文件..."
if [ -d "audio" ]; then
    AUDIO_COUNT=$(find audio -name "*.mp3" -o -name "*.wav" | wc -l)
    if [ $AUDIO_COUNT -gt 0 ]; then
        echo "✅ 找到 $AUDIO_COUNT 个音频文件"
    else
        echo "⚠️ audio目录存在但无音频文件"
    fi
else
    echo "❌ 未找到audio目录"
fi

# 检查系统音频库
echo "🔊 检查系统音频库..."
if command -v apt &> /dev/null; then
    # Ubuntu/Debian
    if dpkg -l | grep -q libasound2-dev; then
        echo "✅ ALSA开发库已安装"
    else
        echo "⚠️ 建议安装: sudo apt install libasound2-dev"
    fi
elif command -v yum &> /dev/null; then
    # CentOS/RHEL
    if rpm -q alsa-lib-devel &> /dev/null; then
        echo "✅ ALSA开发库已安装"
    else
        echo "⚠️ 建议安装: sudo yum install alsa-lib-devel"
    fi
elif command -v dnf &> /dev/null; then
    # Fedora
    if rpm -q alsa-lib-devel &> /dev/null; then
        echo "✅ ALSA开发库已安装"
    else
        echo "⚠️ 建议安装: sudo dnf install alsa-lib-devel"
    fi
elif command -v pacman &> /dev/null; then
    # Arch
    if pacman -Q alsa-lib &> /dev/null; then
        echo "✅ ALSA库已安装"
    else
        echo "⚠️ 建议安装: sudo pacman -S alsa-lib"
    fi
fi

echo ""
echo "🎯 检查完成！"
echo "如果所有项目都显示 ✅，说明环境配置正确"
echo "如果有 ❌ 或 ⚠️，请按照提示安装相应的依赖"
echo ""
echo "💡 提示：运行 ./install_desktop.sh 可以自动安装所有依赖"
